# 输出九九乘法表

expressionWidth = 10  # 每个算式的宽度
count = 9  # 每行算式个数，用于添加空格
maxValue = 9  # 最大数值
# for循环
print("以下for输出for循环的九九乘法表4种：")
# 效果1
for first in range(1, maxValue + 1):
    for second in range(1, first + 1):
        eachExpression = "{0}*{1}={2}".format(second, first,
                                              first * second)  # 单个算式
        print(
            "{0:<{1}}".format(eachExpression, expressionWidth),
            end="")  # 左对齐输出
    print()  # 换行
print("=" * expressionWidth * count)  # 分割线
# 效果2
for first in range(maxValue, 0, -1):
    for second in range(1, first + 1):
        eachExpression = "{0}*{1}={2}".format(second, first,
                                              first * second)  # 单个算式
        print(
            "{0:<{1}}".format(eachExpression, expressionWidth),
            end="")  # 左对齐输出
    print()  # 换行
print("=" * expressionWidth * count)  # 分割线
# 效果3
for first in range(1, maxValue + 1):
    print(
        "{0:<{1}}".format(" ", expressionWidth) * (count - first),
        end="")  # 输出空格
    for second in range(first, 0, -1):
        eachExpression = "{0}*{1}={2}".format(second, first,
                                              first * second)  # 单个算式
        print(
            "{0:<{1}}".format(eachExpression, expressionWidth),
            end="")  # 左对齐输出
    print()  # 换行
print("=" * expressionWidth * count)  # 分割线
# 效果4
for first in range(maxValue, 0, -1):
    print(
        "{0:<{1}}".format(" ", expressionWidth) * (count - first),
        end="")  # 输出空格
    for second in range(first, 0, -1):
        eachExpression = "{0}*{1}={2}".format(second, first,
                                              first * second)  # 单个算式
        print(
            "{0:<{1}}".format(eachExpression, expressionWidth),
            end="")  # 左对齐输出
    print()  # 换行
print("=" * expressionWidth * count)  # 分割线
# while循环
print("以下while输出for循环的九九乘法表4种：")
# 效果1
first = 1
while first < maxValue + 1:
    second = 1
    while second < first + 1:
        eachExpression = "{0}*{1}={2}".format(second, first,
                                              first * second)  # 单个算式
        print(
            "{0:<{1}}".format(eachExpression, expressionWidth),
            end="")  # 左对齐输出
        second += 1
    print()  # 换行
    first += 1
print("=" * expressionWidth * count)  # 分割线
# 效果2
first = maxValue
while first > 0:
    second = 1
    while second < first + 1:
        eachExpression = "{0}*{1}={2}".format(second, first,
                                              first * second)  # 单个算式
        print(
            "{0:<{1}}".format(eachExpression, expressionWidth),
            end="")  # 左对齐输出
        second += 1
    print()  # 换行
    first -= 1
print("=" * expressionWidth * count)  # 分割线
# 效果3
first = 1
while first < maxValue + 1:
    print(
        "{0:<{1}}".format(" ", expressionWidth) * (count - first),
        end="")  # 输出空格
    second = first
    while second > 0:
        eachExpression = "{0}*{1}={2}".format(second, first,
                                              first * second)  # 单个算式
        print(
            "{0:<{1}}".format(eachExpression, expressionWidth),
            end="")  # 左对齐输出
        second -= 1
    print()  # 换行
    first += 1
print("=" * expressionWidth * count)  # 分割线
# 效果4
first = maxValue
while first > 0:
    print(
        "{0:<{1}}".format(" ", expressionWidth) * (count - first),
        end="")  # 输出空格
    second = first
    while second > 0:
        eachExpression = "{0}*{1}={2}".format(second, first,
                                              first * second)  # 单个算式
        print(
            "{0:<{1}}".format(eachExpression, expressionWidth),
            end="")  # 左对齐输出
        second -= 1
    print()  # 换行
    first -= 1
print("=" * expressionWidth * count)  # 分割线
